package com.ag.admin.dao;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;

import com.ag.bean.TbContact;
import com.ag.dao.TbContactDAO;

@Service("adminTbContactDAO")
public class AdminTbContactDAO extends TbContactDAO {
	private static final Logger logger = Logger.getLogger(AdminTbContactDAO.class);
	
	private SessionFactory sessionFacotry;

	@Resource
	public void setSessionFacotry(SessionFactory sessionFacotry) {
		this.sessionFacotry = sessionFacotry;
	}

	@PostConstruct
	public void injectSessionFactory() {
		super.setSessionFactory(sessionFacotry);
	}

	public List<TbContact> findByUName(String queryString) {
		logger.debug("finding TbContact instance by UName ");
		try {
			List<TbContact> results = (List<TbContact>) getHibernateTemplate().find(queryString);
			logger.debug("find by UName successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			logger.error("find by UName failed", re);
			throw re;
		}
	}
}
